const hprose = require('hprose');

const proxyFunc = () => {
  return new Promise((resolve, reject) => {
    const url = think.config('rpc.url');
    try {
      const client = hprose.Client.create(url);
      client.ready(proxy => {
        resolve(proxy);
      });
      think.logger.info('rpc client created');
    } catch (e) {
      reject(e);
    }
  });
};

think.beforeStartServer(async() => {
  think.rpc = await proxyFunc();
});
